export const getViewportOffset = (element: Element) => {
    function getBoundingClientRect(element: Element) {
        if (!element || !element.getBoundingClientRect) {
            return null;
        }
        return element.getBoundingClientRect();
    }
    const doc = document.documentElement;
    const docClientLeft = doc.clientLeft; // 左边框高度
    const docClientTop = doc.clientTop; // 上边框高度
    const box = getBoundingClientRect(element);
    const { left: retLeft, top: rectTop, width: rectWidth, height: rectHeight } = box as DOMRect;

    const left = retLeft + (docClientLeft || 0);
    const top = rectTop + (docClientTop || 0);
    const clientWidth = window.document.documentElement.clientWidth;// 可见宽度
    const clientHeight = window.document.documentElement.clientHeight;//可见高度
    return {
        left,
        top,
        height: rectHeight,
        right: clientWidth - rectWidth - left,
        bottom: clientHeight - rectHeight - top,
        rightIncludeBody: clientWidth - left,
        bottomIncludeBody: clientHeight - top
    };
};